package com.ruoyi.property.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.property.domain.FeeDiscountConfig;
import com.ruoyi.property.service.IFeeDiscountConfigService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 费用折扣Controller
 * 
 * @author sux
 * @date 2021-08-24
 */
@Controller
@RequestMapping("/property/feeDiscountConfig")
public class FeeDiscountConfigController extends BaseController
{
    private String prefix = "property/feeDiscountConfig";

    @Autowired
    private IFeeDiscountConfigService feeDiscountConfigService;

    @RequiresPermissions("property:feeDiscountConfig:view")
    @GetMapping()
    public String feeDiscountConfig()
    {
        return prefix + "/feeDiscountConfig";
    }

    /**
     * 查询费用折扣列表
     */
    @RequiresPermissions("property:feeDiscountConfig:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FeeDiscountConfig feeDiscountConfig)
    {
        startPage();
        List<FeeDiscountConfig> list = feeDiscountConfigService.selectFeeDiscountConfigList(feeDiscountConfig);
        return getDataTable(list);
    }

    /**
     * 导出费用折扣列表
     */
    @RequiresPermissions("property:feeDiscountConfig:export")
    @Log(title = "费用折扣", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FeeDiscountConfig feeDiscountConfig)
    {
        List<FeeDiscountConfig> list = feeDiscountConfigService.selectFeeDiscountConfigList(feeDiscountConfig);
        ExcelUtil<FeeDiscountConfig> util = new ExcelUtil<FeeDiscountConfig>(FeeDiscountConfig.class);
        return util.exportExcel(list, "feeDiscountConfig");
    }

    /**
     * 新增费用折扣
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存费用折扣
     */
    @RequiresPermissions("property:feeDiscountConfig:add")
    @Log(title = "费用折扣", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FeeDiscountConfig feeDiscountConfig)
    {
        return toAjax(feeDiscountConfigService.insertFeeDiscountConfig(feeDiscountConfig));
    }

    /**
     * 修改费用折扣
     */
    @GetMapping("/edit/{feeDiscountId}")
    public String edit(@PathVariable("feeDiscountId") Long feeDiscountId, ModelMap mmap)
    {
        FeeDiscountConfig feeDiscountConfig = feeDiscountConfigService.selectFeeDiscountConfigById(feeDiscountId);
        mmap.put("feeDiscountConfig", feeDiscountConfig);
        return prefix + "/edit";
    }

    /**
     * 修改保存费用折扣
     */
    @RequiresPermissions("property:feeDiscountConfig:edit")
    @Log(title = "费用折扣", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FeeDiscountConfig feeDiscountConfig)
    {
        return toAjax(feeDiscountConfigService.updateFeeDiscountConfig(feeDiscountConfig));
    }

    /**
     * 删除费用折扣
     */
    @RequiresPermissions("property:feeDiscountConfig:remove")
    @Log(title = "费用折扣", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(feeDiscountConfigService.deleteFeeDiscountConfigByIds(ids));
    }
}
